// import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
import {compress} from "three/examples/jsm/libs/fflate.module";

import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';

class roomCtrl {
  constructor() {
    this.init();
  }
  init() {
    this.initScene();
    this.initCamera();
    this.initRenderer();
    // this.initHelper();
    this.initControl();
    this.render();
  }
  initCamera() {
    const camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1 , 1000);
    camera.position.z = 0.01;
    camera.position.z = 4;
    this.camera = camera;
  }
  initScene() {
    const scene = new THREE.Scene();
    this.scene = scene;
  }
  initRenderer(){
    const renderer = new THREE.WebGLRenderer({
      antialias: true,
    });
    renderer.setPixelRatio(2);
    renderer.setClearColor('#e7e7e7');
    renderer.setSize( window.innerWidth, window.innerHeight );
    document.body.appendChild( renderer.domElement );
    this.renderer = renderer;
  }
  render(){
    const renderAction = () => {
      window.requestAnimationFrame(renderAction);
      this.renderer.render(this.scene,this.camera);
    }
    renderAction();
  }
  initHelper(){
    const axisHelper = new THREE.AxisHelper(250);
    this.scene.add(axisHelper);
    const GridHelper = new THREE.GridHelper();
    this.scene.add(GridHelper);
  }
  initControl(){
   this.controls = new OrbitControls(this.camera, this.renderer.domElement);
  }
  addIntoScene(com){
    this.scene.add(com);
  }
}

const roomCtrlIns = new roomCtrl();

const texture = new THREE.TextureLoader().load( 'car_03.png' );
const geometry = new THREE.SphereGeometry( 50, 100, 100 );
geometry.scale(1,1,-1);
const material = new THREE.MeshBasicMaterial( { map: texture } );
const sphere = new THREE.Mesh( geometry, material );
// roomCtrlIns.controls.enableZoom = false;

// const ambient = new THREE.PointLight(0xffffff, 1, 100);
// ambient.position.set(0,1.5,1);
// roomCtrlIns.scene.add(ambient);

// const p = new THREE.PointLightHelper(ambient, 0.2);
// roomCtrlIns.scene.add(p);

roomCtrlIns.addIntoScene( sphere );

//灯光效果
// const a = new THREE.AmbientLight(0xffffff);
// a.position.set(0,1.5,1);
// roomCtrlIns.scene.add(a);

// const ambient = new THREE.PointLight(0xffffff, 1, 100);
// ambient.position.set(0,1.5,1);
// roomCtrlIns.scene.add(ambient);

// const ambient1 = new THREE.PointLight(0xffffff, 1, 100);
// ambient1.position.set(0,1.8,-1);
// roomCtrlIns.scene.add(ambient1);

// const loader = new GLTFLoader();
// const p = new THREE.PointLightHelper(ambient, 0.2);
// roomCtrlIns.scene.add(p);
// const p1 = new THREE.PointLightHelper(ambient1, 0.2);
// roomCtrlIns.scene.add(p1);

// loader.load( '444.glb', function ( gltf ) {

//   roomCtrlIns.scene.add( gltf.scene );

// }, undefined, function ( error ) {

//   console.error( error );

// } );

// const texture = new THREE.TextureLoader().load( '666.jpeg' );
// const material = new THREE.MeshBasicMaterial({
//   // color: '#666666',
//   map: texture,
//   // wireframe: true,
// });
// const geometry = new THREE.SphereGeometry( 3, 32, 32 );
// geometry.scale(1,1,-1);
// // const geometry = new THREE.BoxGeometry(2,2,2);
// const mesh = new THREE.Mesh(geometry, material);
// // mesh.position.y = 1;
// roomCtrlIns.addScene(mesh);
//
// const materialSprite = new THREE.MeshBasicMaterial({
//   color: '#e7e7e7',
//   // map: texture,
// });
// const Sprite = new THREE.Sprite(materialSprite);
// // Sprite.position.y = 2.5;
// Sprite.position.x = 4;
// Sprite.rotateY(Math.PI/2*3);
// roomCtrlIns.addScene(Sprite);

// console.log(roomCtrlIns);
